//
//  UIImage+Extension.swift
//  Sina15
//
//  Created by 盼 on 16/4/20.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

extension UIImage {
    
    class func screenShot()->UIImage {
        
        let window = UIApplication.sharedApplication().keyWindow!
        
        //开启图形上下文
    UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, UIScreen.mainScreen().scale)
        
        //把window上的内容画到图形上下文
        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
        
        //从图形上下文中获取图片
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        //关闭上下文
        UIGraphicsEndImageContext()
        
        return image
    }
}